/* Copyright (c) 2021, National University of Defense Technology. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "par_identity_operator.h"

namespace YHAMG
{

Par_Identity_Operator::Par_Identity_Operator(MPI_Comm comm, int n)
	: Par_Operator(comm),
	size{n, n}
{
}

Par_Identity_Operator::Par_Identity_Operator(MPI_Comm comm, int n, int m)
	: Par_Operator(comm),
	size{n, m}
{
}

int Par_Identity_Operator::InSize() const
{
	return size[1];
}

int Par_Identity_Operator::OutSize() const
{
	return size[0];
}

void Par_Identity_Operator::Apply(const Par_Vector& x, const Par_Vector& y) const
{
	double* xv = x.Loc.values;
	double* yv = y.Loc.values;
	if (size[0] > size[1])
	{
		for (int i = 0; i < size[1]; ++i)
			yv[i] = xv[i];
		for (int i = size[1]; i < size[0]; ++i)
			yv[i] = 0.0;
	}
	else
	{
		for (int i = 0; i < size[0]; ++i)
			yv[i] = xv[i];
	}
}

}